/// @Classname : HcSwitchPage
/// @Author :
/// @Time : 2023-09-08 13:26
/// @Description : //todo

import 'package:flutter/material.dart';
import 'package:hc_ui/widget/image/hc_image.dart';
import 'package:hc_ui/widget/switch/hc_switch.dart';
import 'package:hc_ui/widget/title/hc_full_title.dart';
import 'package:hc_ui/widget/title/hc_title.dart';

class HcSwitchPage extends StatefulWidget {
  const HcSwitchPage({Key? key}) : super(key: key);

  @override
  State<HcSwitchPage> createState() => _HcSwitchPageState();
}

class _HcSwitchPageState extends State<HcSwitchPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: ListView(
        children: [
          HcFullTitle(
            title: "HcSwitch",
            showDot: true,
            showLine: false,
          ),
          HcTitle.dot(
            title: "基础用法",
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              HcSwitch(
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: false,
              ),
              HcSwitch(
                radius: 3,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                radius: 3,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: false,
              ),
            ],
          ),
          HcTitle.dot(
            title: "禁用状态",
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              HcSwitch(
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
                disabled: true,
              ),
              HcSwitch(
                disabled: true,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: false,
              ),
              HcSwitch(
                radius: 3,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
                disabled: true,
              ),
              HcSwitch(
                radius: 3,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: false,
                disabled: true,
              ),
            ],
          ),
          HcTitle.dot(
            title: "修改颜色",
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              HcSwitch(
                activeColor: Colors.purple,
                activeTrackColor: Colors.green,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                activeColor: Colors.purple,
                activeTrackColor: Colors.green,
                disabled: true,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                radius: 3,
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                activeColor: Colors.purple,
                activeTrackColor: Colors.green,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: false,
              ),
              HcSwitch(
                radius: 3,
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                activeColor: Colors.purple,
                activeTrackColor: Colors.green,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: false,
                disabled: true,
              ),
            ],
          ),
          HcTitle.dot(
            title: "显示文字",
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              HcSwitch(
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.track,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.thumb,
                activeColor: Colors.purple,
                activeTrackColor: Colors.green,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                radius: 3,
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.all,
                onChanged: (bool value) {
                  print("value${value}");
                  return Future.value(!value);
                },
                value: false,
              ),
              HcSwitch(
                radius: 3,
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.none,
                value: false,
              ),
            ],
          ),
          HcTitle.dot(
            title: "修改大小",
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              HcSwitch(
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                size: 12,
                showPosition: HcSwitchShowPosition.track,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.thumb,
                activeColor: Colors.purple,
                activeTrackColor: Colors.green,
                disabled: true,
                size: 18,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                radius: 3,
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                activeWidget: Icon(Icons.ac_unit),
                inactiveWidget: Icon(Icons.sunny),
                size: 24,
                showPosition: HcSwitchShowPosition.all,
                onChanged: (bool value) {
                  print("value${value}");
                  return Future.value(!value);
                },
                value: false,
              ),
              HcSwitch(
                radius: 3,
                size: 36,
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                activeWidget: Icon(Icons.ac_unit),
                inactiveWidget: Icon(Icons.sunny),
                showPosition: HcSwitchShowPosition.none,
                value: false,
                disabled: true,
              ),
            ],
          ),
          HcTitle.dot(
            title: "特殊用法",
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceAround,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              HcSwitch(
                thumbWidget: HcImage(
                  src: "assets/images/icon.jpeg",
                ),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.track,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                thumbWidget: HcImage(
                  src: "assets/images/icon.jpeg",
                ),
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.thumb,
                activeColor: Colors.purple,
                activeTrackColor: Colors.green,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                value: true,
              ),
              HcSwitch(
                radius: 3,
                thumbWidget: HcImage(
                  src: "assets/images/icon.jpeg",
                  borderRadius: BorderRadius.circular(3),
                ),
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                showLoading: true,
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.all,
                onChanged: (bool value) async {
                  print("value${value}");

                  await Future.delayed(Duration(seconds: 2), () {
                    print('延迟1秒后执行');
                  });
                  return Future.value(!value);
                },
                value: false,
              ),
              HcSwitch(
                radius: 3,
                inactiveThumbColor: Colors.yellow,
                inactiveTrackColor: Colors.grey,
                onChanged: (bool value) {
                  return Future.value(!value);
                },
                activeWidget: Text("开"),
                inactiveWidget: Text("关"),
                showPosition: HcSwitchShowPosition.none,
                value: false,
                disabled: true,
              ),
            ],
          )
        ],
      ),

      // floatingActionButton: FloatingActionButton(
      //   onPressed: _incrementCounter,
      //   tooltip: 'Increment',
      //   child: const Icon(Icons.add),
      // ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
